import record
import analisadorWave
import wave

rec1 = record.Record('/dev/dsp')
rec2 = record.Record('/dev/dsp1')
rec3 = record.Record('/dev/dsp2')

def disparaThreads():
	rec1.gravar()
	rec2.gravar()
	rec3.gravar()
	
def paraThreads():
	rec1.parar()
	rec2.parar()
	rec3.parar()
	
def armazenaWaves():
	rec1.save2wave('rec1.wav')
	rec2.save2wave('rec2.wav')
	rec3.save2wave('rec3.wav')
	
def analisaWaves():
	w1 = analisadorWave.AnalisadorWave(wave.open('rec1.wav'))
	w2 = analisadorWave.AnalisadorWave(wave.open('rec2.wav'))
	w3 = analisadorWave.AnalisadorWave(wave.open('rec3.wav'))
	w1.analisar()
	w2.analisar()
	w3.analisar()
	
	print "Wave 1:"
	w1.imprimeResultados()
	print "-------\nWave 2:"
	w2.imprimeResultados()
	print "-------\nWave 3:"
	w3.imprimeResultados()
	t1 = w1.segundoMaiorAmostra()
	t2 = w2.segundoMaiorAmostra()
	t3 = w3.segundoMaiorAmostra()
	print '\n----------------------'
	print 'onboard para meio: %s' % (t2-t1)
	print 'onboard para ultima: %s' % (t2-t3)
	print 'meio para ultima: %s' % (t1-t3)
	print 'onboard e meio com o mesmo microfone'
	print 'diferenca segundos ultima para as outras: %s' % (w1.segundosTotais()-w3.segundosTotais())
	


###########################
###		EXECUCOES		###
disparaThreads()
raw_input("ENTER para parar as threads...")
paraThreads()
armazenaWaves()
analisaWaves()

